//package com.qzsoft.fileServers.controller;
//
//import com.mongodb.gridfs.GridFSFile;
//import com.qzsoft.fileServers.service.GridFSService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import javax.servlet.http.HttpServletResponse;
//import java.util.HashMap;
//import java.util.Map;
//
//@Api(value="/gridFs", tags="mongodb文件服务接口")
//@RestController
//@RequestMapping("/gridFs")
//public class GridFSController {
//
//    @Autowired
//    public GridFSService gridFSService;
//
//    @ApiOperation(value = "保存文件", notes = "保存文件并返回ID")
//    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
//    public Map<String,Object> save(@RequestParam(value = "file", required = true) MultipartFile file) {
//        Map<String,Object> map = new HashMap<>();
//        try {
//            GridFSFile store = gridFSService.save(file);
//            map.put("success",true);
//            map.put("id",store.getId().toString());
//        } catch (Exception e) {
//            map.put("success",false);
//            map.put("msg",e.getMessage());
//            e.printStackTrace();
//        }
//        return map;
//    }
//
//    @ApiOperation(value = "下载文件", notes = "根据ID返回文件流下载")
//    @GetMapping(value = "/{id}")
//    public void get(@PathVariable String id, HttpServletResponse res) throws Exception {
//        gridFSService.get(id,res);
//    }
//
//    @ApiOperation(value = "删除文件", notes = "根据ID删除对应的文件")
//    @DeleteMapping(value = "/{id}",produces = MediaType.APPLICATION_JSON_VALUE)
//    public Map<String,Object> delete(@PathVariable String id) {
//        Map<String,Object> map = new HashMap<>();
//        try {
//            gridFSService.delete(id);
//            map.put("success",true);
//        } catch (Exception e) {
//            map.put("success",false);
//            map.put("msg",e.getMessage());
//            e.printStackTrace();
//        }
//        return map;
//    }
//}